package cn.cf.kxx.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.cf.kxx.R;
import cn.cf.kxx.model.Group;
import cn.cf.kxx.model.Valve;

public class GridGroupAdapter extends BaseAdapter {
    private Context mContext;
    private List<Group> mDataList;

    public GridGroupAdapter(Context context, List<Group> dataList) {
        mContext = context;
        mDataList = dataList;
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.group_item, parent, false);
            holder = new ViewHolder();
            holder.gid = convertView.findViewById(R.id.gid);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Group item = mDataList.get(position);
        holder.gid.setText(item.getName());
        if(!TextUtils.isEmpty(item.getSelect())){
            convertView.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.bg_circle_group_sel));
        }else{
            convertView.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.bg_circle_group));
        }

        return convertView;
    }

    class ViewHolder {
        TextView gid;
    }
}
